package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.Setmeal;
import com.xrit.sunnyday.service.SetmealMobileService;
import com.xrit.sunnyday.service.SetmealService;
import com.xrit.sunnyday.utils.QiNiuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 移动端套餐管理
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealMobileController {

    @Reference
    private SetmealMobileService setmealMobileService;

    /**
     * 查询所有
     */
    @GetMapping("/getSetmeal")
    public Result getSetmeal(){
        //1.查询所有套餐
        List<Setmeal> list = setmealMobileService.findAll();
        //2.拼接图片全路径
        list.forEach(a->{
            a.setImg(QiNiuUtils.DOMAIN + a.getImg());
        });
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);
    }

    /**
     * 查询套餐详情(五表联查)
     */
    @GetMapping("/findDetailById")
    public Result findDetailById(int id){
        //1.调用服务查询详情
        Setmeal setmeal = setmealMobileService.findDetailById(id);
        //2.设置图片完整路径
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        //3.返回
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }

    @Reference
    SetmealService setmealService;
    /**
     * 查询套餐的基本信息
     */
    @GetMapping("/findById")
    public Result findById(int id){
        //根据id查询套餐
        Setmeal setmeal = setmealService.findById(id);
        //后台设置套餐图片显示路径
        setmeal.setImg(QiNiuUtils.DOMAIN+setmeal.getImg());
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }


}
